/* 机构工作范围 */
import leftCard from '@/components/jiGouCard.vue'
import { ref } from 'vue'
import { typeTree, twoChhildren } from '@/types/typeData'
import { treeApi } from '@/api/organizationManage'
import { getMap } from '@/api/workArea'
import { IFanWei } from '@/types/data'
export default function workAreaFn() {
  /* 全屏加载 */
  let loading = ref<boolean>(true)
  /* 获取机构列表 */
  // 定义 树形 数据
  const defaultProps = {
    children: 'children',
    label: 'name',
  }
  // 机构列表
  let organizationList = ref<typeTree | undefined>()
  // 获取
  const getOrganizationList = async (): Promise<void> => {
    const res = await treeApi()
    loading.value = false
    organizationList.value = JSON.parse(res.data.data as any)
  }

  /* 点击切换地图信息 */
  let mapInfo = ref<IFanWei>()
  const handleNodeClick = async (data: twoChhildren): Promise<void> => {
    const res = await getMap(data.id)

    res.data.data.polygon = res.data.data.polygon.map((item: any) => {
      return {
        lng: item.longitude,
        lat: item.latitude
      }
    });
    mapInfo.value = res.data.data
  }


  return { mapInfo, leftCard, getOrganizationList, organizationList, defaultProps, loading, handleNodeClick }
}